﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using SMO.Models;

namespace SMO.Models.SimplObject
{
    public class MembershipRepository
    {
        private SMO_LinQDataContext datacontent = new SMO_LinQDataContext();
        public IQueryable<Membership> GetAll()
        {
            return datacontent.Memberships;
        }

        public Membership GetByMembershipID(string id)
        {
            return datacontent.Memberships.SingleOrDefault(s => s.MembershipId.ToString().Trim() == id.Trim());
        }

        public IQueryable<Membership> GetByUserID(string id)
        {
            return datacontent.Memberships.Where(s => s.UserId.ToString().Trim() == id.Trim());
        }

        public Membership GetFirst()
        {
            return datacontent.Memberships.FirstOrDefault();
        }

        public void Add(Membership membership)
        {
            datacontent.Memberships.InsertOnSubmit(membership);
        }

        public void Delete(Membership membership)
        {
            datacontent.Memberships.DeleteOnSubmit(membership);
        }

        public void Save()
        {
            datacontent.SubmitChanges();
        } 
    }
}
